﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected string sArticleTitle = string.Empty;
    protected string sArticleContent= string.Empty;

    protected string leftBlockTitle, rightBlockTitle, centerBlockTitle;
    protected string leftBlockText, rtBlockText, centerBlockText;
    protected string leftBlockImg, rtBlockImg, centerBlockImg;

    protected IEnumerable<string> Images;

    protected string sKeywords = string.Empty;
    protected string sDescription = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        //Load pageData
        Dal.arParams.Clear();
        
        Dal.arParams.Add((int)((ArtCube)this.Master).FUNC.LangID); // Curent language
        DataSet DS = Dal.ExecuteDBspDS("GetMainPage", Dal.arParams);

        // If not null - fill fields
        if (DS != null)

            if (DS.Tables.Count > 0)

                if (DS.Tables[0].Rows.Count > 0)
                {
                    // Get data with linq
                    Images =
                (from row in DS.Tables[0].AsEnumerable() select row.Field<string>("Image"));
                }

            // Set Article
            if(DS.Tables.Count>1)
            if (DS.Tables[1].Rows.Count > 0)
            {
                DataRow Row = DS.Tables[1].Rows[0];
                Title= Row["PageTitle"].ToString();
                sKeywords = Row["Keywords"].ToString();
                sDescription= Row["Description"].ToString();

                sArticleTitle= Row["Title"].ToString();
                sArticleContent = Row["Content"].ToString();
            }
       
        // three blocks

            // Set Article
            if (DS.Tables.Count >2)
                if (DS.Tables[2].Rows.Count > 0)
                {
                    DataRow Row = DS.Tables[2].Rows[0];
                    leftBlockImg = Row["Img"].ToString();
                    leftBlockTitle = Row["Title"].ToString();
                    leftBlockText = Row["Content"].ToString();
                    
                    Row = DS.Tables[2].Rows[1];
                    centerBlockImg = Row["Img"].ToString();
                    centerBlockTitle = Row["Title"].ToString();
                    centerBlockText = Row["Content"].ToString();
                    
                    Row = DS.Tables[2].Rows[2];
                    rtBlockImg = Row["Img"].ToString();
                    rightBlockTitle = Row["Title"].ToString();
                    rtBlockText = Row["Content"].ToString();
                }
    }
}